import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ParsedNginxRequest {
    public String method;
    public String uri;
    public String protocol;

    public ParsedNginxRequest(String method, String uri, String protocol) {
        this.method = method;
        this.uri = uri;
        this.protocol = protocol;
    }

    public static ParsedNginxRequest parseRequest(String requestStr) throws ParseException {
        Pattern pattern = Pattern.compile("(.*?)\\s+(.*?)\\s+(.*)");
        Matcher matcher = pattern.matcher(requestStr);
        if (matcher.find()) {
            ParsedNginxRequest result = new ParsedNginxRequest(matcher.group(1), matcher.group(2), matcher.group(3));
            return result;
        } else throw new ParseException("Cannot parse request string: " + requestStr, 0);
    }
}
